#ifndef CLIENTAPPLICATION_H
#define CLIENTAPPLICATION_H

#include "autoload.h"
#include "sockettransport.h"
#include "Logic/session.h"
#include "recievethread.h"

class ClientApplication : public QObject
{
    Q_OBJECT
private:
    QTcpSocket* socket;
    QHostAddress* remoteAddress;
    MainExeqtor* executor;
    SocketTransport* transport;
    RecieveThread* receiveThread;

    bool started;
    bool connected;
    bool sync;
    QString address;
    QString port;
    Session* context;
    static ClientApplication * client;
    ClientApplication(Session* context, QString address, QString port);
public:
    void Init();
    void StartClient();
    void StopClient();

    static void CreateClient(Session* context, QString address, QString port)
    {
        if (ClientApplication::client == NULL)
            ClientApplication::client = new ClientApplication(context, address, port);
    }

    MainExeqtor* Executor()
    {
        return executor;
    }

    SocketTransport* Transport()
    {
        return transport;
    }

    Session* getSession()
    {
        return context;
    }

    static ClientApplication* Instance()
    {
        return client;
    }

    bool getStarted()
    {
        return started;
    }

    bool getConnected()
    {
        return connected;
    }
signals:
    void authorization();
    void registration();
    void roomsList();
    void joinRoom();
    void getUsers();
    void sendMessage();
    void getMessages();
    void fail(QString);

public slots:
    void ProceedAuthorization();
    void ProceedRegistration();
    void ProceedRoomsList();
    void ProceedJoinRoom();
    void ProceedGetUsers();
    void ProceedSendMessage();
    void ProceedGetMessages();
    void Failed(QString);
};

#endif // CLIENTAPPLICATION_H
